package com.cloud.pole.weixin.wechat.message;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

import com.cloud.pole.weixin.wechat.WXXmlElementName;

public class Msg4Image extends Msg {

	// 图片消息媒体id
	private String mediaId;
	
	/**
	 * 开发者调用
	 * */
	public Msg4Image() {
		this.head = new Msg4Head();
		this.head.setMsgType(Msg.MSG_TYPE_IMAGE);//设置消息类型
	}
	
	/**
	 * 程序内部调用
	 * */
	public Msg4Image(Msg4Head head) {
		this.head = head;
	}

	@Override
	public void write(Document document) {
		Element root = document.createElement(WXXmlElementName.ROOT);
		head.write(root, document);	
		Element imageElement = document.createElement(WXXmlElementName.IMAGE);
		Element mediaidElement = document.createElement(WXXmlElementName.MEDIAID);
		mediaidElement.setTextContent(this.mediaId);
		imageElement.appendChild(mediaidElement);
		root.appendChild(imageElement);
		document.appendChild(root);
	}
	
	@Override
	public void read(Document document) {
		this.mediaId = getElementContent(document, WXXmlElementName.MEDIAID);
	}

	/**
	 * @return the mediaId
	 */
	public String getMediaId() {
		return mediaId;
	}

	/**
	 * @param mediaId the mediaId to set
	 */
	public void setMediaId(String mediaId) {
		this.mediaId = mediaId;
	}
}
